# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=ruff
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.0.284
pkgrel=1
pkgdesc="An extremely fast Python linter, written in Rust"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/charliermarsh/ruff'
license=('spdx:MIT')
options=('!strip')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
  "${MINGW_PACKAGE_PREFIX}-python-maturin"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
source=("${_realname}-${pkgver}.tar.gz::$url/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('841e55268ffd5d3d3113d5f32590f46a974aab5811736ed01542340f80a42901')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  tar -xf "${_realname}-${pkgver}.tar.gz" || true
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo fetch --locked
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  maturin build --release --strip --locked --all-features
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo test --release --frozen --all-features
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" target/wheels/*.whl

  install -vDm 644 LICENSE -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
  install -vDm 644 README.md -t "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/"
}
